package com.cby.operation.login.data

import android.os.Parcel
import android.os.Parcelable

/**
 * sdk内使用的用户信息实体类
 *
 * @property userId String?
 * @property nick String?
 * @property loginType String?
 * @property token String?
 * @property accessToken String?
 * @constructor
 */
data class InternalUser(

    /**
     * 用户ID
     */
    var userId: String?,

    /**
     * 用户昵称
     */
    var nick: String?,

    /**
     * 用户登录方式
     */
    var loginType: String?,

    /**
     * 用户登录token
     */
    val token: String?,

    /**
     * 对外校验码
     */
    var accessToken: String? = null

) : Parcelable{

    constructor(parcel: Parcel) : this(
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readString(),
        parcel.readString()
    ) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(userId)
        parcel.writeString(nick)
        parcel.writeString(loginType)
        parcel.writeString(token)
        parcel.writeString(accessToken)
    }

    override fun describeContents(): Int {
        return 0
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as InternalUser

        if (userId != other.userId) return false
        if (nick != other.nick) return false
        if (loginType != other.loginType) return false
        if (token != other.token) return false
        if (accessToken != other.accessToken) return false

        return true
    }

    override fun hashCode(): Int {
        var result = userId?.hashCode() ?: 0
        result = 31 * result + (nick?.hashCode() ?: 0)
        result = 31 * result + (loginType?.hashCode() ?: 0)
        result = 31 * result + (token?.hashCode() ?: 0)
        result = 31 * result + (accessToken?.hashCode() ?: 0)
        return result
    }

    override fun toString(): String {
        return "InternalUser(userId=$userId, nick=$nick, loginType=$loginType, token=$token, accessToken=$accessToken)"
    }

    companion object CREATOR : Parcelable.Creator<InternalUser> {
        override fun createFromParcel(parcel: Parcel): InternalUser {
            return InternalUser(parcel)
        }

        override fun newArray(size: Int): Array<InternalUser?> {
            return arrayOfNulls(size)
        }
    }


}
